//控制小程序中图片大小
export const formatRichText = (html) => {
	let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
		if (match.search(/style=/gi) == -1) {
			match = match.replace(/\<img/gi, '<img style=""');
		}
		return match;
	});

	newContent = newContent.replace(/style="/gi, '$& max-width:100% !important; ');
	newContent = newContent.replace(/<br[^>]*\/>/gi, '');
	return newContent;
}
// 跳转
export const navigateTo = (url) => {
	uni.navigateTo({
		url: url
	});
}
// storage
export const storage = {
	setStorage: (key, data, callback = () => {}) => {
		uni.setStorage({
			key: key,
			data: data,
			success: function(e) {
				callback(e);
			}
		});
	},
	getStorage: (key, callback = () => {}) => {
		uni.getStorage({
			key: key,
			success: (e) => {
				callback(e);
			}
		});
	}
}
export const getKey = (key, value = '?') => {
	let url = decodeURIComponent(location.href);
	if (url.includes(value)) {
		let str = url.split(value)[1];
		let strArr = str.split('-');
		for (let i of strArr) {
			let _k = i.split("=")[0];
			if (_k == key) {
				return decodeURIComponent(i.split("=")[1]);
			}
		}
	}
	return null;
}
